package com.example.demo.service.Impl;

import com.example.demo.entity.Dept;
import com.example.demo.mapper.DeptMapper;
import com.example.demo.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
@Service
public class DeptServiceImpl implements DeptService {
//    private DeptDaoImpl deptDao = new DeptDaoImpl();
    @Autowired
    private DeptMapper deptMapper;

    /**
     * 查询 depts
     * @return
     */
    @Override
    public List<Dept> queryDeptList(){
        List<Dept> Depts = deptMapper.queryDeptList();
        return Depts;
//        List<Dept> deptslist = new ArrayList<>();
//        for (Dept dept : Depts) {
//            String[] parts = dept.split(",");
//            Integer id = Integer.valueOf(parts[0]);
//            String name = parts[1];
//            LocalDateTime time = LocalDateTime.parse(parts[2], DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
//            Dept dept = new Dept(id, name, time);
//            deptslist.add(dept);
//        }
//        return deptslist;
    }

    /**
     * 删除 dept
     * @param id
     */
    @Override
    public void delete(Integer id) {
        deptMapper.delete(id);
    }

    /**
     * 新增 dept
     * @param dept
     */
    @Override
    public void add(Dept dept) {
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.add(dept);
    }

    /**
     * 数据回显
     * @param id
     * @return
     */
    @Override
    public Dept getInfo(Integer id) {
        return deptMapper.getById(id);
    }

    @Override
    public void update(Dept dept) {
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.update(dept);
    }
}
